import 'dart:io';
import 'dart:ui';
import 'package:flutter/cupertino.dart' ;
import 'package:flutter/cupertino.dart' as prefix0;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:signature/signature.dart';
import 'package:flutter/cupertino.dart';
import 'dart:convert';
import 'package:zhrs/utils/http_utils.dart';
import 'package:dio/dio.dart';
import 'package:zhrs/utils/windowsSize.dart';
class  Sigmatures extends StatefulWidget {
  @override
  _Sigmatures createState() => _Sigmatures();
}

class _Sigmatures extends State<Sigmatures> {
  var _signatureCanvas = Signature( height: windowsSize.mapViewHeight*0.6,width: windowsSize.mapViewWidth*0.9,

  );

  Future<BaseResp> getSignatureInfo(String base64Str) async{
    String url='';
    Map data={'image':base64Str,'image_type':'BASE64'};
    Options options=Options();
    options.contentType=ContentType.json;
    return await HttpUtils().post(url,
        data: data,
        options: options
    );
  }

  @override
  Widget build(BuildContext context) {

    return  Container(
      child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                //SIGNATURE CANVAS
                Container(
                  height: windowsSize.mapViewHeight*0.6,
                  width: windowsSize.mapViewWidth*0.9,
                  color: Colors.white,
                  child: _signatureCanvas,
                ) ,
                //OK AND CLEAR BUTTONS
                Container(
                    decoration: const BoxDecoration(
                      // color: Colors.white,
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      mainAxisSize: MainAxisSize.max,
                      children: <Widget>[
                        //SHOW EXPORTED IMAGE IN NEW ROUTE
                       FlatButton(
                           color: Colors.blue,
                           child: Text("提交",style: TextStyle(color: Colors.white),),
                         onPressed: () async {
                           if (_signatureCanvas.isNotEmpty) {
                             await _signatureCanvas.exportBytes().then((val){
                               String base64str=base64Encode(val);
                               print("：：：："+base64str);
                               Navigator.pop(context,base64str);
                             });
                             /*  Navigator.of(context).push(
                              MaterialPageRoute(
                                builder: (BuildContext context) {
                                  return Scaffold(
                                    appBar: AppBar(),
                                    body: Container(
                                      color: Colors.grey[300],
                                      child: Image.memory(data),
                                    ),
                                  );
                                },
                              ),
                            );*/
                           }
                         },
                       ),
                        //CLEAR CANVAS
                        Container(
                          child: buildButton("清除", onPressed)
                        ),
                      ],
                    )),
              ],
            ),
          );




  }

  onPressed ()
  {
    return _signatureCanvas.clear();
  }
}
Widget buildButton(
    String text,
    Function onPressed, {
      Color color = Colors.blue,
    }) {
  return FlatButton(
    color: color,
    child: Text(text,style:TextStyle(color: Colors.white),),
    onPressed: onPressed,
  );
}
